<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .father {
            width: 200px;
            height: 200px;
            background-color: pink;
        }

        .son {
            width: 100px;
            height: 100px;
            background-color: orange;
        }
    </style>
</head>
<body>
    <div class="father">
        <div class="son"></div>
    </div>

    <script>
        var f_div = document.querySelector('.father');
        var s_div = document.querySelector('.son');

        f_div.addEventListener('click',function(event) {
            console.log('father 点击回调方法被调用');
            // 标准写法： 停止冒泡 事件的传递
             event.stopPropagation();
            // 停止冒泡事件 IE678之前使用的， 但是之后也可以使用
            event.cancelBubble = true;
        })
        s_div.onclick = function(event) {
            console.log('son 点击回到方法被调用');
        }
        document.onclick = function(event) {
            console.log('doucment 点击回调方法被调用');
        }

        //阻止事件冒泡的兼容方案
        function compatibility(event) {
            if (event && event.stopPropagation) {
                event.stopPropagation();
            } else {
                window.event.cancelBubble = true;
            }
        }
    </script>
</body>
</html>